package ru.xeden.web.html.module;

import ru.xeden.web.html.Constants;
import ru.xeden.web.request.IRequest;

/**
 * 
 * @author evga
 *
 */
public class UrlPieces
{
    private String[] pieces;
    private String url; 
    int cursor;
    private String pageName;
    
    public UrlPieces(IRequest request)
    {
        this.url = request.getPath();
        pageName = request.getParameter(Constants.PAGE_PARAM_NAME);
        if (url.startsWith("/"))
        {
            url = url.substring(1);
        }
        this.pieces = url.split("/");
        this.cursor=0;
    }
    
    public String getPageName()
    {
        return pageName;
    }
    
    public String getCurrentPiece()
    {
        return pieces[cursor];
    }
    
    public boolean hasNext()
    {
        return (pieces.length - 1) > cursor;
    }
    
    public void next()
    {
        cursor++;
    }

    public void previous()
    {
        cursor--;
    }
    
    public void reset()
    {
        cursor = 0;
    }
    
    public int getSize()
    {
        return pieces.length;
    }
    
    public int getPosition()
    {
        return cursor;
    }
    
    public String getUrl()
    {
        return url;
    }
}
